{include file="public/header" /}
<style type="text/css">
    .uploader-list {

        margin-left: -15px;

    }



    .uploader-list .info {

        position: relative;

        margin-top: -25px;

        background-color: black;

        color: white;

        filter: alpha(Opacity=80);

        -moz-opacity: 0.5;

        opacity: 0.5;

        width: 100px;

        height: 25px;

        text-align: center;

        display: none;

    }



    .uploader-list .handle {

        position: relative;

        background-color: black;

        color: white;

        filter: alpha(Opacity=80);

        -moz-opacity: 0.5;

        opacity: 0.5;

        width: 100px;

        text-align: right;

        height: 18px;

        margin-bottom: -18px;

        display: none;

    }



    .uploader-list .handle i {

        margin-right: 5px;

    }



    .uploader-list .handle i:hover {

        cursor: pointer;

    }



    .uploader-list .file-iteme {

        margin: 12px 0 0 15px;

        padding: 1px;

        float: left;

    }
</style>

<body style="background-color: #ffffff">
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>大分类</label>
                    <div class="layui-input-inline">
                        <select name="cate" lay-verify="required" lay-filter="cate">
                            <option>选择分类</option>
                            {foreach $cate as $v}
                            <option value="{$v.id}" {if !empty($row.cate) && $row.cate==$v.id}selected{/if}>{$v.name}
                            </option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>子分类</label>
                    <div class="layui-input-inline">
                        <select name="cateson" lay-verify="required" lay-filter="cateson">
                            <option>选择子分类</option>
                            {foreach $cateson as $v}
                            <option value="{$v.id}" {if !empty($row.catsonsid) && $row.catsonsid==$v.id}selected{/if}>
                                {$v.name}
                            </option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                {if $row.isnone <= 0} <div class="layui-form-item" id="province">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>省份</label>
                    <div class="layui-input-inline">
                        <select name="province" data-area="" lay-filter="province">
                            <option value="">选择省</option>
                            {foreach $province as $v}
                            <option value="{$v.area_code}" {if !empty($row.provinceid) &&
                                $row.provinceid==$v.area_code}selected{/if}>
                                {$v.name}
                            </option>
                            {/foreach}
                        </select>
                    </div>
        </div>
        <div class="layui-form-item" id="city">
            <label for="L_choose_name" class="layui-form-label">
                <span class="x-red">*</span>城市</label>
            <div class="layui-input-inline">
                <select name="city" data-area="" lay-filter="city">
                    <option value="">选择城市</option>
                    {foreach $city as $v}
                    <option value="{$v.area_code}" {if !empty($row.cityid) && $row.cityid==$v.area_code}selected{/if}>
                        {$v.name}
                    </option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item" id="area">
            <label for="L_choose_name" class="layui-form-label">
                <span class="x-red">*</span>区域</label>
            <div class="layui-input-inline">
                <select name="area" data-area="" lay-filter="area">
                    <option value="">选择区域</option>
                    {foreach $area as $v}
                    <option value="{$v.area_code}" {if !empty($row.areaid) && $row.areaid==$v.area_code}selected{/if}>
                        {$v.name}
                    </option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item" id="street">
            <label for="L_choose_name" class="layui-form-label">
                <span class="x-red">*</span>街道(不设置则按区域设置价格)</label>
            <div class="layui-input-inline">
                <select name="street" data-area="" lay-filter="street">
                    <option value="">选择街道</option>
                    {foreach $street as $v}
                    <option value="{$v.id}" {if !empty($row.streetid) && $row.streetid==$v.id}selected{/if}>
                        {$v.name}
                    </option>
                    {/foreach}
                </select>
            </div>
        </div>
        {/if}
        <div class="layui-form-item">
            <label for="L_choose_name" class="layui-form-label">
                <span class="x-red">*</span>标题：</label>
            <div class="layui-input-inline">
                <input type="text" required="" lay-verify="required" autocomplete="off" class="layui-input"
                    value="{$row.names|default=''}" name="names" />
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_choose_name" class="layui-form-label">
                <span class="x-red">*</span>描述：</label>
            <div class="layui-input-inline">
                <input type="text" required="" lay-verify="required" autocomplete="off" class="layui-input"
                    value="{$row.descs|default=''}" name="descs" />
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_choose_name" class="layui-form-label">
                <span class="x-red">*</span>单位：</label>
            <div class="layui-input-inline">
                <input type="text" required="" lay-verify="required" autocomplete="off" class="layui-input"
                    value="{$row.unit|default=''}" name="unit" />
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_choose_name" class="layui-form-label">
                <span class="x-red">*</span>起始价格：</label>
            <div class="layui-input-inline">
                <input type="number" required="" lay-verify="required" autocomplete="off" class="layui-input"
                    value="{$row.price|default=''}" name="price" />
            </div>
        </div>
        <div class="layui-form-item">
            <label for="cover" class="layui-form-label">
                <span class="x-red">*</span>封面</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-sm" id="test1">图片上传</button>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;width: 88%">
                        预览图：
                        <div class="layui-upload-list uploader-list" style="overflow: auto;" id="uploader-list1">
                            {if !empty($row.images)}
                            <div class="file-iteme">
                                <div class="handle" style="display: none;">
                                    <i class="layui-icon layui-icon-delete"></i>
                                </div><img style="width: 100px;height: 100px;" src="{$row.images}">
                                <input type="hidden" name="images" value="{$row.images}">
                            </div>
                            {/if}
                        </div>
                    </blockquote>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="cover" class="layui-form-label">
                <span class="x-red">*</span>详情</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-sm" id="test2">多图片上传</button>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;width: 88%">
                        预览图：
                        <div class="layui-upload-list uploader-list" style="overflow: auto;" id="uploader-list">
                            {if !empty($row.details)}
                            {foreach $row.details as $v}
                            <div class="file-iteme">
                                <div class="handle" style="display: none;">
                                    <i class="layui-icon layui-icon-delete"></i>
                                </div><img style="width: 100px;height: 100px;" src="{$v}">
                                <input type="hidden" name="details[]" value="{$v}">
                            </div>
                            {/foreach}
                            {/if}
                        </div>
                    </blockquote>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <input type="hidden" value="{$row.id|default=''}" name="id">
            <button class="layui-btn layui-btn-sm" lay-filter="add" lay-submit="">提交</button>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <button type="button" class="layui-btn layui-btn-sm layui-btn layui-btn-sm-primary" onclick="IframeClose()">取消</button>

        </div>
        </form>
    </div>
    </div>

    {include file="public/footer" /}
    <script src="/static/leyedit/Layui-KnifeZ/layui.js"></script>
    <script src="/static/leyedit/ace/ace.js"></script>
    <script>
        // 删除图片
        $(document).on("click", ".file-iteme .handle", function (event) {
            $(this).parent().remove();
        });
        $(document).on("mouseenter mouseleave", ".file-iteme", function (event) {
            if (event.type === "mouseenter") {
                //鼠标悬浮
                $(this).children(".info").fadeIn("fast");
                $(this).children(".handle").fadeIn("fast");
            } else if (event.type === "mouseleave") {
                //鼠标离开
                $(this).children(".info").hide();
                $(this).children(".handle").hide();
            }
        });
        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;
            //图片上传
            var demoListView = $('#demoList'),
                uploadListIns = upload.render({
                    elem: '#test2'
                    , url: '/Base/upload_img'
                    , multiple: true
                    , before: function (obj) {
                        layer.msg('图片上传中...', {
                            icon: 16,
                            shade: 0.01,
                            time: 0
                        })
                    }
                    , done: function (res) {
                        if (res.code == 0) {
                            //上传完毕
                            $('#uploader-list').append(
                                '<div id="" class="file-iteme">' +
                                '<div class="handle"><i class="layui-icon layui-icon-delete"></i></div>' +
                                '<img style="width: 100px;height: 100px;" src=' + res.data.src + '>' +
                                '<input type="hidden" name="details[]" value="' + res.data.src + '"></div>'
                            );
                        }
                        layer.close(layer.msg());//关闭上传提示窗口
                    }
                });
            var demoListViews = $('#demoList1'),
                uploadListIns = upload.render({
                    elem: '#test1'
                    , url: '/Base/upload_img'
                    , multiple: true
                    , before: function (obj) {
                        layer.msg('图片上传中...', {
                            icon: 16,
                            shade: 0.01,
                            time: 0
                        })
                    }
                    , done: function (res) {
                        if (res.code == 0) {
                            //上传完毕
                            $('#uploader-list1').html(
                                '<div id="" class="file-iteme">' +
                                '<div class="handle"><i class="layui-icon layui-icon-delete"></i></div>' +
                                '<img style="width: 100px;height: 100px;" src=' + res.data.src + '>' +
                                '<input type="hidden" name="images" value="' + res.data.src + '"></div>'
                            );
                        }
                        layer.close(layer.msg());//关闭上传提示窗口
                    }
                });
        });

        layui.use(['layedit', 'layer', 'jquery', 'form'], function () {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer;
            var layedit = layui.layedit;
            //监听大分类更改子分类
            form.on('select(cate)', function (data) {
                $.ajax({
                    type: 'get',
                    url: '/base/getcateson',
                    data: { id: data.value },
                    success: function (res) {
                        if (res.code == 0 && data.value > 0) {
                            var str = '<option value="">请选择子分类</option>';
                            $.each(res.data, function (i, obj) {
                                str += '<option value="' + obj.id;
                                str += '">' + obj.name;
                                if (obj.province_text) {
                                    str += '(' + obj.province_text + obj.city_text + obj.area_text + obj.street_text + ')';
                                }
                                str += '</option>';
                            });
                            $('select[name="cateson"]').html(str);
                            form.render();
                        }
                    }
                });
                return false;
            });
            //监听子分类隐藏显示省市区
            form.on('select(cateson)', function (data) {
                $.ajax({
                    type: 'get',
                    url: '/base/getsons',
                    data: { id: data.value },
                    success: function (res) {
                        if (res.code == 0 && data.value > 0) {
                            if (res.data.provinceid > 0) {
                                $("#province").hide();
                                $("#area").hide();
                                $("#city").hide();
                                $("#street").hide();
                            } else {
                                $("#province").show();
                                $("#area").show();
                                $("#city").show();
                                $("#street").show();
                            }
                        }
                    }
                }); return false;
            });
            //监听省份选择市区
            form.on('select(province)', function (data) {
                $.ajax({
                    type: 'get',
                    url: '/base/getarea',
                    data: { id: data.value, level: 2 },
                    success: function (res) {
                        if (res.code == 0 && data.value > 0) {
                            var str = '<option value="">请选择城市</option>';
                            $.each(res.data, function (i, obj) {
                                str += '<option value="' + obj.area_code;
                                str += '">' + obj.name;
                                str += '</option>';
                            });
                            $('select[name="city"]').html(str);
                            form.render();
                        }
                    }
                });
                return false;
            });

            form.on('select(city)', function (data) {
                $.ajax({
                    type: 'get',
                    url: '/base/getarea',
                    data: { id: data.value, level: 3 },
                    success: function (res) {
                        if (res.code == 0 && data.value > 0) {
                            var str = '<option value="">请选择区域</option>';
                            $.each(res.data, function (i, obj) {
                                str += '<option value="' + obj.area_code;
                                str += '">' + obj.name;
                                str += '</option>';
                            });
                            $('select[name="area"]').html(str);
                            form.render();
                        }
                    }
                });
                return false;
            });


            form.on('select(area)', function (data) {
                $.ajax({
                    type: 'get',
                    url: '/base/getarea',
                    data: { id: data.value, level: 4 },
                    success: function (res) {
                        if (res.code == 0 && data.value > 0) {
                            var str = '<option value="">请选择街道</option>';
                            $.each(res.data, function (i, obj) {
                                str += '<option value="' + obj.id;
                                str += '">' + obj.name;
                                str += '</option>';
                            });
                            $('select[name="street"]').html(str);
                            form.render();
                        }
                    }
                });
                return false;
            });
            layedit.set({
                //暴露layupload参数设置接口 --详细查看layupload参数说明
                uploadImage: {
                    url: '/Base/upload_img',
                    accept: 'image',
                    acceptMime: 'image/*',
                    exts: 'jpg|png|gif|bmp|jpeg|webp',
                    size: '100240'
                }
                //右键删除图片/视频时的回调参数，post到后台删除服务器文件等操作，
                //传递参数：
                //图片： imgpath --图片路径
                //视频： filepath --视频路径 imgpath --封面路径
                , calldel: {
                    url: '/Base/upload_img'
                }
                //开发者模式 --默认为false
                , devmode: false
                //插入代码设置
                , codeConfig: {
                    hide: true,  //是否显示编码语言选择框
                    default: 'javascript' //hide为true时的默认语言格式
                }
                , tool: ['strong', 'italic', 'underline', 'del', 'addhr', '|', 'fontFomatt', 'colorpicker', 'face'
                    , '|', 'left', 'center', 'right', '|', 'link', 'unlink', 'images', 'image_alt', 'anchors'
                    , '|', 'table', 'fullScreen'
                ]
                , height: '300px'
            });
            var intro = layedit.build('intro');
            var infodesc = layedit.build('infodesc');
            //监听提交
            form.on('submit(add)', function (data) {
                data.field.intro = layedit.getContent(intro);
                data.field.infodesc = layedit.getContent(infodesc);
                //发异步，把数据提交给php
                $.ajax({
                    'type': 'post',
                    data: data.field,
                    success: function (res) {
                        console.log(res);
                        if (res.status == 0) {
                            layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000 });
                        }
                    }
                });
                return false;
            });
        });
    </script>

</body>

</html>